# -*- coding: utf-8 -*-

import sys
sys.path.append('../')
from common.config import *
from db.mysql import MysqlClient
from itertools import product
from common.helper import Helper

class Spider(object):
    def __init__(self):
        self.mysql = MysqlClient()
        self.name = "泰无忧肝病险"
    # 生成产品数据
    def genProductInfo(self):
        num = 0
        prices = ["162.00","290.00","517.00","990.00","322.00","577.00","1031.00","1977.00"]
        plan = {
            "planA":{
                # 年龄段
                "year": ["18-30", "31-40", "41-50", "51-55"],
                # 肝病保额
                "liverDisease": ["50000"],
                # 意外保额
                "accidentDeath": ["100000"],
                # 保障期限
                "expire": ["1年"],
                # 交费方式
                "payType": ["年交"],
            },
            "planB":{
                # 年龄段
                "year": ["18-30", "31-40", "41-50", "51-55"],
                # 肝病保额
                "liverDisease": ["100000"],
                # 意外保额
                "accidentDeath": ["200000"],
                # 保障期限
                "expire": ["1年"],
                # 交费方式
                "payType": ["年交"],

            }


        }
        for k in plan:
            for v  in product( plan[k]["year"],plan[k]["liverDisease"],plan[k]["accidentDeath"],plan[k]["expire"],plan[k]["payType"]):
                price = (prices[num])
                data = Helper.formatProductInfo( plan[k], v )
                data["price"] = price
                self.mysql.cursor.execute( domain[self.name]["insert_sql"].format( **data ))
                self.mysql._conn.commit()
                print(  domain[self.name]["insert_sql"].format( **data ) )
                num+=1

